package com.ruoyi.project.device.cargoarea.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.cargoarea.domain.BasCargoArea;
import com.ruoyi.project.device.cargoarea.service.IBasCargoAreaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货区管理Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/area")
public class BasCargoAreaController extends BaseController
{
    private String prefix = "device/area";

    @Autowired
    private IBasCargoAreaService basCargoAreaService;

    @GetMapping()
    public String area()
    {
        return prefix + "/area";
    }

    /**
     * 查询货区管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasCargoArea basCargoArea)
    {
        startPage();
        List<BasCargoArea> list = basCargoAreaService.selectBasCargoAreaList(basCargoArea);
        return getDataTable(list);
    }

    /**
     * 导出货区管理列表
     */
    @Log(title = "货区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasCargoArea basCargoArea)
    {
        List<BasCargoArea> list = basCargoAreaService.selectBasCargoAreaList(basCargoArea);
        ExcelUtil<BasCargoArea> util = new ExcelUtil<BasCargoArea>(BasCargoArea.class);
        return util.exportExcel(list, "货区管理数据");
    }

    /**
     * 新增货区管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货区管理
     */
    @Log(title = "货区管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasCargoArea basCargoArea)
    {
        return toAjax(basCargoAreaService.insertBasCargoArea(basCargoArea));
    }

    /**
     * 修改货区管理
     */
    @GetMapping("/edit/{cargoAreaId}")
    public String edit(@PathVariable("cargoAreaId") String cargoAreaId, ModelMap mmap)
    {
        BasCargoArea basCargoArea = basCargoAreaService.selectBasCargoAreaByCargoAreaId(cargoAreaId);
        mmap.put("basCargoArea", basCargoArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存货区管理
     */
    @Log(title = "货区管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasCargoArea basCargoArea)
    {
        return toAjax(basCargoAreaService.updateBasCargoArea(basCargoArea));
    }

    /**
     * 删除货区管理
     */
    @Log(title = "货区管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basCargoAreaService.deleteBasCargoAreaByCargoAreaIds(ids));
    }
}
